import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:largefriends/pages/lf_test/lf_test_logic.dart';
import 'package:largefriends/widgets/lf_app_bar.dart';
import 'package:largefriends/widgets/lf_horizontal_scroll/lf_horizontal_scroll_widget.dart';

class LfGridScrollTest extends StatefulWidget {
  const LfGridScrollTest({super.key});

  @override
  State<LfGridScrollTest> createState() => _LfGridScrollTestState();
}

class _LfGridScrollTestState extends State<LfGridScrollTest> {
  final logic = Get.put(LfTestLogic());

  RxInt selectedValue = 0.obs;

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
        child: Obx(() => Scaffold(
              appBar: lfAppBar(
                  title:
                      "${logic.selectedList.length}---${selectedValue.value}",
                  centerTitle: true),
              body: LfHorizontalScrollWidget(
                list: logic.testList,
                selectedValue: selectedValue.value,
                onTap: (value) {
                  // lfLogger.printInfo(info: value.toString());
                  if (containsNum(selectedValue.value, value)) {
                    selectedValue.value -= value;
                  } else {
                    selectedValue.value += value;
                  }
                },
              ),
            )),
        onWillPop: () async {
          Get.back();
          return false;
        });
  }
}

class TestDataType {
  final int value;
  final String text;

  TestDataType({required this.value, required this.text});
}

bool containsNum(int number, int check) {
  if ((check & (check - 1)) != 0) {
    return false;
  }
  return (number & check) != 0;
}
